﻿@model NewsLetterSubscriptionListModel
@using Telerik.Web.Mvc.UI

@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
}
@using (Html.BeginForm())
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Administration/Content/images/ico-promotions.png")" alt="" />
            @T("Admin.Promotions.newsLetterSubscriptions")
        </div>
            <div class="options">
                <a href="@Url.Action("ExportCsv")" class="t-button">@T("Admin.Common.ExportToCsv")</a>
                <button type="submit" id="importcsv" name="importcsv" value="importcsv" class="t-button">@T("Admin.Common.ImportFromCsv")</button>
            </div>
    </div>
    <table width="100%">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.SearchEmail):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => Model.SearchEmail)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <button type="submit" id="search-newsLetterSubscriptions" value="search-newsLetterSubscriptions" class="t-button">@T("Admin.Common.Search")</button>     
            </td>
        </tr>
    </table>
    <p>
    </p>
    <table class="adminContent">
        <tr>
            <td>
                @(Html.Telerik().Grid<NewsLetterSubscriptionModel>()
                        .Name("newsLetterSubscriptions-grid")
                        .BindTo(Model.NewsLetterSubscriptions.Data)
                        .DataKeys(x =>
                        {
                            x.Add(y => y.Id).RouteKey("Id");
                        })
                        .Columns(columns =>
                        {
                            columns.Bound(x => x.Email);
                            columns.Bound(x => x.Active);
                            columns.Bound(x => x.CreatedOn)
                                .ReadOnly();
                            columns.Command(commands =>
                            {
                                commands.Edit();
                                commands.Delete();
                            }).Width(180);

                        })
                        .Pageable(settings => settings.Total(Model.NewsLetterSubscriptions.Total).PageSize(gridPageSize).Position(GridPagerPosition.Both))
                        .DataBinding(dataBinding => dataBinding.Ajax()
                            .Select("SubscriptionList", "NewsLetterSubscription")
                            .Update("SubscriptionUpdate", "NewsLetterSubscription")
                            .Delete("SubscriptionDelete", "NewsLetterSubscription"))
                        .ClientEvents(events => events.OnDataBinding("onDataBinding"))
                        .EnableCustomBinding(true))
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#search-newsLetterSubscriptions').click(function () {
                var grid = $('#newsLetterSubscriptions-grid').data('tGrid');
                grid.ajaxRequest();
                return false;
            });
        });

        function onDataBinding(e) {
            var searchModel = {
                SearchEmail: $('#@Html.FieldIdFor(model => model.SearchEmail)').val()
            };
            e.data = searchModel;
        }
    </script>  
}

@*import emails form*@
@{Html.Telerik().Window()
        .Name("importcsv-window")
        .Title(T("Admin.Common.ImportFromCsv").Text)
        .Content(@<text>
        @using (Html.BeginForm("ImportCsv", "NewsLetterSubscription", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <table style="text-align: left;">
            <tr>
                <td>
                    CSV file:
                </td>
                <td>
                    <input type="file" id="importcsvfile" name="importcsvfile"/>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button type="submit" class="t-button t-state-default">@T("Admin.Common.ImportFromCsv")</button>
                </td>
            </tr>
        </table>
        }
        </text>)
        .Width(400)
        .Draggable(true)
        .Modal(true)
        .Visible(false)
        .Render();
}

<script type="text/javascript">
    $(document).ready(function () {

        $("#importcsv").click(function (e) {
            e.preventDefault();
            $('#importcsv-window').data('tWindow').center().open();
        });
    });
</script>
